const express=require("express");
const _=require("lodash");

const router=express.Router();

let phones=[
    {id:202201,name:"ZET U880",price:999.5},
    {id:202201,name:"Meizu 魅蓝",price:1198.5},
    {id:202201,name:"Huwei honer 8X",price:1399.7}
];

router.get("/",(req,res,next)=>{
    res.render("pdt",{phones});
});

router.get("/delete/:id",(req,res,next)=>{
    let index=_.findIndex(phones,{id:parseInt(req.params.id)});
    //从集合中删除
    phones.splice(index,1);
});

module.exports=router;